<?php

	// TITLE: Tickets AUTO MODEL
	// FILE: scaffolding/model/tickets.php
	// AUTHOR: AUTOGEN
	// CREATED: 2015/04/20 07:49:57
	// DESCRIPTION: 
	// REQUIREMENTS: 

	$createTickets = function($con, $tickets) {
		$sql = 'INSERT INTO tickets (id, event_id, ticket_price) VALUES (';
		$sql .= $tickets->getId() . ', ';
		$sql .= $tickets->getEventId() . ', ';
		$sql .= $tickets->getTicketPrice() . ')';
		$sql .= ')';
		$result = mysqli_query($con, $sql);
		$id = ($result) ? mysqli_insert_id($con) : $result;
		mysqli_close($con);
		return $id;
	};

	$readTickets = function($con, $id) {
		$sql = 'SELECT * FROM tickets WHERE id = ' . $id;
		$results = mysqli_query($con, $sql);
		mysqli_close($con);
		if ($results) {
			$result = mysqli_fetch_array($results);
			$tickets = new Tickets();
			$tickets->setId(result[0]);
			$tickets->setEventId($dbio->select($readEvent(result[1])));
			$tickets->setTicketPrice(result[2]);
		} else {
			$tickets = false;
		}
		return $tickets;
	};

	$updateTickets = function($con, $tickets) {
		$sql = 'UPDATE tickets SET ';
		$sql .= 'id = ' . $tickets->getId() . ', ';
		$sql .= 'event_id = ' . $tickets->getEventId() . ', ';
		$sql .= 'ticket_price = ' . $tickets->getTicketPrice() ;
		$sql .= 'WHERE id = ' . id;
		$result = mysqli_query($con, $sql);
		mysqli_close($con);
		return $result;
	};

	$deleteTickets = function($con, $id) {
		$sql = 'DELETE FROM tickets WHERE id = ' . $id;
		$result = mysqli_query($con, $sql);
		mysqli_close($con);
		return $result;
	};

	$listTickets = function($con) {
		$sql = 'SELECT * FROM tickets';
		$results = mysqli_query($con, $sql);
		mysqli_close($con);
		if ($results) {
			$ticketss = array();
			while ($result = mysqli_fetch_array($results)) {
				$tickets = new Tickets();
				$tickets->setId(result[0]);
				$tickets->setEventId($dbio->select($readEvent(result[1])));
				$tickets->setTicketPrice(result[2]);
				$ticketss[] = tickets;
			}// end while
		} else {
			$ticketss = false;
		}
		return $ticketss;
	};

